;(function ($) {
	//入口
	$.fn.actGroupSave=function(options){
    	//创建对象
		var act = new myActGroupSave(this, options);  
		act.getDefaultValue();
	}
	
	//构造函数
    var myActGroupSave = function(ele, opt) {   	
    	//选择器对象    	
        this.$element=ele;   
        //默认参数
        this.defaults = {
    		dataBack:function(){},
            returnBack:function(){} 
        },      
        //初始化参数
        this.options = $.extend({}, this.defaults, opt);
    }

    //属性方法
    myActGroupSave.prototype = {
		defaultValue:{},
    	getDefaultValue:function(){
    		var $this=this;
    		var $opt=$this.options;
    		var $t=this;
    		var el=$t.$element
    		
    		var param={};
            param.arg={"jdh":$opt.data.jdh,"operation":"default"};
            $.HSAPI_CALLPROCEDURE2(param,"SPAct_group_SAVE",{},function(data){
                if(data.RETURN==1){ 
                    $t.defaultValue=data.ct_group[0];  
                    $t.html();
                }else{
                    $.HSAPI_ALERT(data.MSG);
                }
            },function(data){
                $.HSAPI_ALERT(JSON.stringify(data));
            })
    	},
    	//添加房间
    	html:function(){ 
    		var $this=this;
    		var $opt=$this.options;
    		
    		$this.$element.addClass("modal").attr("tabindex","-2").attr("data-backdrop","static");
    		var html = '<div class="modal-dialog" style="min-width:700px;">'+    
				'<div class="modal-content">'+
					'<div class="modal-header no-padding">'+
						'<div class="table-header">'+
							'<span id="title-dialog" style="font-size:16px;">'+$.i18n.propJsp("修改")+'</span>'+ 
						'</div>'+
					'</div>'+
					'<div class="modal-body" style="height:240px">'+     
					   '<form id="frm_guestListEdit" class="form-horizontal" onSubmit="return false;">'+
					   	'<div class="col-xs-12">'+
							'<div class="profile-user-info">'+
					   			'<div class="profile-info-row">'+
							   		'<div class="profile-info-name" style="text-align:center">'+$.i18n.propJsp("接待号")+'</div>'+
									'<div class="profile-info-value">'+
										'<span class="editable" id="jdh"></span>'+
									'</div>'+
								'</div>'+
							'</div>'+
						'</div>'+
						'<div class="col-xs-12">'+
							'<div class="profile-user-info">'+
					   			'<div class="profile-info-row">'+
							   		'<div class="profile-info-name" style="text-align:center">'+$.i18n.propJsp("姓名")+'</div>'+
									'<div class="profile-info-value">'+
										'<span class="editable" id="gname"></span>'+
									'</div>'+
								'</div>'+
							'</div>'+
						'</div>'+
						'<div class="col-xs-12">'+
					   		'<div class="profile-user-info">'+
						   		'<div class="profile-info-row">'+
									'<div class="profile-info-name" style="text-align:center">'+$.i18n.propJsp("电话")+'</div>'+
									'<div class="profile-info-value">'+
										'<span class="editable" id="tel"></span>'+
									'</div>'+
								'</div>'+
							'</div>'+
						'</div>'+
						'<div class="col-xs-12">'+
							'<div class="profile-user-info">'+
								'<div class="profile-info-row">'+
									'<div class="profile-info-name" style="text-align:center">'+$.i18n.propJsp("备注1")+'</div>'+
									'<div class="profile-info-value">'+
										'<span class="editable" id="remark1"></span>'+
									'</div>'+
								'</div>'+
							 '</div>'+
						'</div>'+
						'<div class="col-xs-12">'+ 
							'<div class="profile-user-info">'+
								'<div class="profile-info-row">'+
									'<div class="profile-info-name" style="text-align:center">'+$.i18n.propJsp("备注2")+'</div>'+
									'<div class="profile-info-value">'+
										'<span class="editable" id="remark2"></span>'+
									'</div>'+
								'</div>'+
							 '</div>'+
						'</div>'+
						'<div class="col-xs-6">'+ 
							'<div class="profile-user-info">'+
								'<div class="profile-info-row">'+ 
									'<div class="profile-info-name" style="text-align:center">'+$.i18n.propJsp("销售员")+'</div>'+
									'<div class="profile-info-value">'+
										'<span class="editable" id="sales"></span>'+
									'</div>'+
								'</div>'+
							 '</div>'+
						'</div>'+
					   '</form>'+
					'</div>'+
					'<div class="modal-footer">'+
						'<div class="btn-group">'+
							'<button id="modalBtnCancel" type="button" class="btn btn-sm btn-default">'+  
								'<i class="ace-icon fa fa-undo"></i>'+
								$.i18n.propJsp("取消")+ 
							'</button>'+
						'</div>'+
					'</div>'+
				'</div>'+
			'</div>';
    		$this.$element.html(html);
    		
    		$this.bindEvent(); 
    		
		},
		bindEvent:function(){
			var $this=this;
    		var $opt=$this.options;
    		var $t=this;
    		var el=$t.$element
			
    		//初始化
    		for(var item in $t.defaultValue){
    			el.find("#"+item).html($opt.data[item]); 
    		}
    		el.find("#tel,#gname,#remark1,#remark2,#sales").editable({ 
			 	type: 'text',
			 	mode: 'inline',
			 	onEditableSave: function (field, row, oldValue, $el) {}
	                
			});
    		
    		//执行保存
    		el.find("#tel,#gname,#remark1,#remark2,#sales").on('save', function(e, params) {
    			var param={};
    			param.arg={"jdh":$opt.data.jdh}; 
    			param.ct_group={};
    			param.ct_group[e.currentTarget.id]=params.submitValue; 
                
                $.HSAPI_CALLPROCEDURE2(param,"SPAct_group_SAVE",{},function(data){
                    if(data.RETURN==1){
                        $opt.dataBack();
                    }else{
                        $opt.dataBack();
                        $.HSAPI_ALERT(data.MSG);
                    }
                },function(data){
                    $.HSAPI_ALERT(JSON.stringify(data));
                })
    		});
    		
    		//取消
			el.find("#modalBtnCancel").click(function(){
				$opt.returnBack(); 
			});
		},
	}	
})(jQuery);